﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Retirement_myPorfolio : System.Web.UI.Page
{
    public List<Policy> policies = new List<Policy>();
    protected void Page_Load(object sender, EventArgs e)
    {
        int custId = -1;

        if (Session["userID"] == null)
        {
            custId = 15369472;//TODO GET FROM SESSION

        }
        else
        {
            custId = Convert.ToInt32(Session["userID"]);

        }

        List<Policy> policise = Policy.getPolicy(custId);

         this.policies = Policy.getPolicy(custId);
         if (policies == null || policies.Count == 0)
         {
             return;
         }
         else
         {

             List<Fund> listFund = new List<Fund>();

             foreach (Policy p in policise)
             {
                 List<Fund> funds = Fund.getPortfolioFunds(p.policyNo, "ACTIVE");
                 foreach (Fund f in funds)
                 {
                     f.currentFundPrice = FundPrice.getLastPrice(f.code);
                     f.bidPrice = f.currentFundPrice.bidPrice;
                     f.offerPrice = f.currentFundPrice.offerPrice;
                     f.valuationDate = f.currentFundPrice.valuationDate;
                     listFund.Add(f);
                 }

             }

             this.gv_funds.DataSource = listFund;
             this.gv_funds.DataBind();
         }
    }

}